package com.mall.service;

import com.mall.mapper.goodsMapper;
import com.mall.mapper.subCateMapper;
import com.mall.pojo.subCate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class subCateService {
    @Autowired
    private subCateMapper subCateMapper;
    @Autowired
    private goodsMapper goodsMapper;
    public List<subCate> findAll() {
        List<subCate> subCates = subCateMapper.findAll();
        for (subCate subCate : subCates) {
            subCate.setGoods(goodsMapper.findBySubId(subCate.getId()));
        }
        return subCates;
    }
    public subCate findById(int id) {
        subCate subCate= subCateMapper.findById(id);
        subCate.setGoods(goodsMapper.findBySubId(subCate.getId()));
        return subCate;
    }

    public List<subCate> findByParentId(int parentId) {
        List<subCate> subCates = subCateMapper.findByParentId(parentId);
        for (subCate subCate : subCates) {
            subCate.setGoods(goodsMapper.findBySubId(subCate.getId()));
        }
        return subCates;
    }
}
